package iut.acy.retardeleve;
import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.util.Log;
import android.widget.ListView;
import android.widget.Toast;

public class CallbackFiller {

	ArrayList<Retard> list;
	ListView lvListe;
	Activity activity;
	
	public CallbackFiller(Activity activity, ArrayList<Retard> list, ListView lvListe){
		this.activity = activity;
		this.list = list;
		this.lvListe = lvListe;
	}
	
	public void execute(JSONObject response){
		list.clear();
			try {
				for(int i = 0; i < response.length(); i++){
					JSONObject temp;
					temp = new JSONObject(response.getString(""+i));
					list.add(new Retard(temp.getString("nomRetardataire"),
										temp.getString("prenomRetardataire"),
										temp.getString("travail"),
										temp.getInt("dureeRetard"),
										temp.getInt("heureCours")));
				}
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		RetardAdapter adapter = new RetardAdapter(activity, list);
		lvListe.setAdapter(adapter);
	}
}
